import math
from pylab import *
import time

dir='/home/jcfernandez/resultados/eps1/u20/AMPL/W2.0/CONNECT/NEO/connect/'
name='densidadconnectA100.dat'
dir='/Users/jonk/Documents/Trabajo/resultados/eps1/u100/AMPL/W2.0/CONNECT/NEO/'
name='nconnectA60.dat'
#name='conectA100.dat'
#gamma0=0.01
omega=2.0
ymax=100.0
x2 = arange(0,10.0,0.01)
n=0
pt=None
toRad=math.pi/180.0
ion()
fig = plt.figure()
ax = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
for line in file(dir+name):
    if n%10 == 0:
        line=line.replace('\n','')
        val=line.split(' ')
        res=[]
        for v in val:
            if v!='':
                res.append(float(v))
        x=[]
        y=[]
        step=180./(len(res)-1)
        for i in range(1,len(res)):
            x.append((i-1)*step+0.5*step)
            fracArea=(math.cos(toRad*(x[i-1]-0.5*step))-(math.cos(toRad*(x[i-1]+0.5*step))))*0.5
            y.append(res[i]/fracArea/(1000.0*999.0))
        
        if n==0:
            #print plot(x,y)
            ax.bar(x,y)
            x1=x[:]
            y1=y[:]
            ax.plot(x1,y1,'r-')
           # ax.axis([0,180,0,ymax])
          #  ax2.plot(x2,gamma0*sin(omega*x2))
          #  line2, = ax2.plot(0,0,'ro')

        else:
            ax.clear()
            ax.bar(x,y)
            ax.plot(x1,y1,'r-')
            #ax.axis([0,180,0,ymax])
          #  line2.set_xdata(res[0])
          #  line2.set_ydata(gamma0*sin(omega*res[0]))
            draw()
    n+=1
